﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using ThresholdAssistant.DataContract.Result;
using ThresholdAssistant.WebAPI.Models;
using ThresholdAssistant.WebAPI.Service;

namespace ThresholdAssistant.WebAPI.Controllers
{
    /// <summary>
    /// 阈值控制器
    /// </summary>
    [Route("api/threshold")]
    public class ThresholdController : BaseController
    {
        /// <summary>
        /// 阈值服务
        /// </summary>
        public ThresholdService ThresholdService { get; set; }

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("get-list")]
        [AllowAnonymous]
        public async Task<ContractResult<IEnumerable<ThresholdData>>> GetListAsync(GetThresholdListParam param)
        {
            return await ThresholdService.GetListAsync(param);
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("add")]
        [AllowAnonymous]
        public async Task<ContractResult<long>> AddAsync(AddThresholdParam param)
        {
            return await ThresholdService.AddAsync(param);
        }

        /// <summary>
        /// 单个
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("get-info")]
        [AllowAnonymous]
        public async Task<ContractResult<ThresholdData>> GetInfoAsync(GetThresholdInfoParam param)
        {
            return await ThresholdService.GetInfoAsync(param.Id);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("update")]
        [AllowAnonymous]
        public async Task<ContractResult> UpdateAsync(UpdateThresholdParam param)
        {
            return await ThresholdService.UpdateAsync(param);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        [AllowAnonymous]
        public async Task<ContractResult> DeleteAsync(DeleteThresholdParam param)
        {
            return await ThresholdService.DeleteAsync(param.Id);
        }

        #region 其他
        public DataClearService DataClearService { get; set; }
        /// <summary>
        /// job测试
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("JobTest")]
        [AllowAnonymous]
        public async Task<object> JobTestAsync(UpdateConfigParam param)
        {
            await DataClearService.ExecuteAsync();
            return "success";
        }

        #endregion
    }
}
